package pl.edu.pw.perg.compinfodb.manager;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import pl.edu.pw.perg.compinfodb.dao.ComplexElementDAO;
import pl.edu.pw.perg.compinfodb.entities.ComplexElement;
import pl.edu.pw.perg.compinfodb.entities.PhysicalElement;
import pl.edu.pw.perg.compinfodb.entities.VirtualElement;

public class ComplexElementManager extends GenericManager<ComplexElement> implements IComplexElementManager {

	private IVirtualElementManager virtualElementManager;
	private IPhysicalElementManager physicalElementManager;
	
	public IVirtualElementManager getVirtualElementManager() {
		return virtualElementManager;
	}

	public void setVirtualElementManager(
			IVirtualElementManager virtualElementManager) {
		this.virtualElementManager = virtualElementManager;
	}

	public IPhysicalElementManager getPhysicalElementManager() {
		return physicalElementManager;
	}

	public void setPhysicalElementManager(
			IPhysicalElementManager physicalElementManager) {
		this.physicalElementManager = physicalElementManager;
	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public ComplexElement getComplexByVirtual(VirtualElement ve){
		return ((ComplexElementDAO) getGenericDAO()).getComplexByVirtual(ve);
	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public ComplexElement getComplexByPhysical(PhysicalElement pe){
		return ((ComplexElementDAO) getGenericDAO()).getComplexByPhysical(pe);
	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public PhysicalElement getPhysicalByVirtual(VirtualElement ve){
		ComplexElement ce = getComplexByVirtual(ve);
		return ce == null ? null : physicalElementManager.findById(ce.getPeId());
	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public VirtualElement getVirtualByPhysical(PhysicalElement pe){
		ComplexElement ce = getComplexByPhysical(pe);
		return ce == null ? null : virtualElementManager.findById(ce.getVeId());
	}
}
